extends Node

# 简单的音频测试脚本
# 用于验证背景音乐文件是否能正确加载和播放

func _ready():
	print("=== 音频测试开始 ===")
	test_audio_loading()

func test_audio_loading():
	"""测试音频文件加载"""
	print("测试音频文件加载...")
	
	# 尝试加载音频文件
	var audio_path = "res://assets/audio/background.mp3"
	var audio_stream = load(audio_path)
	
	if audio_stream:
		print("✅ 音频文件加载成功: ", audio_path)
		print("音频流类型: ", audio_stream.get_class())
		
		# 创建AudioStreamPlayer进行测试
		var player = AudioStreamPlayer.new()
		add_child(player)
		
		player.stream = audio_stream
		player.volume_db = -10.0
		player.bus = "Master"
		
		print("开始播放测试音频...")
		player.play()
		
		# 检查播放状态
		await get_tree().create_timer(1.0).timeout
		if player.playing:
			print("✅ 音频正在播放")
		else:
			print("❌ 音频播放失败")
		
		# 停止播放
		await get_tree().create_timer(3.0).timeout
		player.stop()
		print("音频测试完成")
		
	else:
		print("❌ 音频文件加载失败: ", audio_path)
		print("请检查文件路径和格式")
	
	print("=== 音频测试结束 ===")

func _input(event):
	"""按T键重新测试"""
	if event is InputEventKey and event.pressed:
		if event.keycode == KEY_T:
			print("重新开始音频测试...")
			test_audio_loading()